/**
 * Created by IntelliJ IDEA.
 * User: dinesh
 * Date: July 20, 2013
 * Time: 11:14:41 AM
 * To change this template use File | Settings | File Templates.
 */


/***************************/

  //global vars
	var form = $("#frmData");


$(document).ready(function(){

    disableForm("frmData");
} );
var timeoutHnd;
var flAuto = false;
function doSearch(ev) {
    if (!flAuto)
    return;
    var elem = ev.target || ev.srcElement;
    if (timeoutHnd)
    clearTimeout(timeoutHnd);
    timeoutHnd = setTimeout(reloadGrid, 500);
}
function reloadGrid() {
    var searchCriteriaLotId = document.getElementById("searchCriteria.lotName").value;
    var searchCriteriaCode = document.getElementById("searchCriteria.code").value;

    var params =encodeURIComponent("lotId") + "="+searchCriteriaLotId+"&code="+searchCriteriaCode;
    ajaxPost("?tld/getTldList", params, function(data) {
			var response =JSON.parse(data);
			if (response.status==false) {
				return;
			}
            $("#formBody").html("" ) ;
            $("#formBody").html(response.tableHtml) ;
              disableForm("frmData");
             handleDefaultButtons("gridclick");
		});

}
function enableAutosubmit(state) {
    flAuto = state;
    document.getElementById("submitButton").disabled = state;

}
function initialize(fnAfterInit) {
    //clearForm("frmData");
   // clearValidate();
    disableForm("frmData");
    handleDefaultButtons("gridclick");
}
function clearBt(){
    $("#messagePanel").removeClass();
    $("#messagePanel").html("" ) ;
    $("#formBody").html("" ) ;
    initialize();
}
function edit(){
    enableForm("frmData");
    handleDefaultButtons("edit");   
}

function save(){
        var params = serializeForm("frmData") ;
        ajaxPost("?tld/updateCard", params, function(data) {

			var response =JSON.parse(data);

			if (response.status==false) {


				return;
			}

			// Success
			//actionResponse = response;
            $("#messagePanel").removeClass();
            $("#messagePanel").addClass(response.type);
            $("#messagePanel").html(response.message ) ;
           

			initialize();
            reloadGrid();

		});


    handleDefaultButtons("save");
}


function closePage(){
    window.location.href="?home";
}

function onLoad(){
     initialize();
     enforcePrivileges();
    reloadGrid();
}
onLoad();